import Mock from 'mockjs'
import '@/mock/extend'

const user = Mock.mock({
  accountNonExpired: true,
  accountNonLocked: true,
  actorId: "admin",
  administrator: false,
  credentialsNonExpired: true,
  enabled: true,
  nickname: "@ADMIN",
  password: "{bcrypt}$2a$10$.c/TiWuSmvwitqxBZsF5guQ6qQn08E1b1Aldff/LEb.dkeR0b4RGq",
  username: "admin"
})
Mock.mock(`${process.env.VUE_APP_API_BASE_URL}/login`, 'post', ({body}) => {
  let data = {
    result:{}
  }
  const {username, password} = JSON.parse(body)
  let success = false
  if (username === 'admin' && password === '123456') {
    success = true
    // result.data.permissions = [{id: 'queryForm', operation: ['add', 'edit']}]
    // result.data.roles = [{id: 'admin', operation: ['add', 'edit', 'delete']}]
  } else if (username === 'test' && password === '888888') {
    success = true
    // result.data.permissions = [{id: 'queryForm', operation: ['add', 'edit']}]
    // result.data.roles = [{id: 'test', operation: ['add', 'edit', 'delete']}]
  } else {
    success = false
  }
  if (success) {
    data.code = 200
    data.success = true
    data.message = Mock.mock('@TIMEFIX').CN + '，欢迎回来'
    data.result.user = user
    data.result.refreshToken = 'Authorization:' + Math.random()
    data.result.token = 'Authorization:' + Math.random()
    // result.data.expireAt = new Date(new Date().getTime() + 30 * 60 * 1000)
  } else {
    data.code = -1
    data.success = false
    data.message = '账户名或密码错误（admin/888888 or test/888888）'
  }
  return data
})
Mock.mock(`${process.env.VUE_APP_API_BASE_URL}/user/logout`, 'post', () => {
  return {
    code: 200,
    message: "成功",
    result: null,
    success: true,
  }
})